﻿using AgencyManagerSystem.AsmType;
using AgencyManagerSystem.Common;
using AgencyManagerSystem.DataFetcher;
using AgencyManagerSystem.DataUpdater;
using AgencyManagerSystem.Model;
using System;

namespace AgencyManagerSystem.Core
{
    public abstract class StatusDocManager<T> : DocManager<T> where T : StatusModel
    {
        private StatusUpdater<T> updater;
        public StatusDocManager():base() { }
        protected override BaseUpdater<T> InjectionUpdater()
        {
            this.updater = InjectionStatusUpdater();
            return this.updater;
        }
        protected abstract StatusUpdater<T> InjectionStatusUpdater();

        public virtual AsmObject<T> Close(T model,string reason)
        {
            string message;
            bool result = updater.Close(model.AutoId,reason, out message);
            if (!result)
            {
                DBHelper.Commit( false);
                return new AsmObject<T>() { Message = message, Result = AmsCode.InnError };
            }
            else
            {
                return new AsmObject<T>() { Message = "操作成功", Result = AmsCode.Succ, Data = model };
            }
        }
    }
}
